//
//  YZCardModel.m
//  VET
//
//  Created by Lam BG on 2018/7/25.
//  Copyright © 2018年 YZ. All rights reserved.
//

#import "YZCardModel.h"

#import "NSString+DisplayTime.h"

@interface YZCardModel ()

@property (nonatomic, copy) NSString *option;

@end

@implementation YZCardModel

+ (instancetype)initWithType:(WBCardType)cardType {
    
    YZCardModel *model = [[YZCardModel alloc] init];
    model.cardType = cardType;
    
    return model;
}

+ (NSDictionary *)mj_replacedKeyFromPropertyName {
    
    return @{
             @"updateTime" : @"time",
             
             };
}

#pragma mark - getter

- (NSString *)cardTitle {
    
    if (self.cardType == WBCardTypeSwine) {
        return @"猪只健康卡";
    }
    
    if (self.cardType == WBCardTypeSwinery) {
        return @"猪群健康卡";
    }
    
    if (self.cardType == WBCardTypeDieOut) {
        return @"死淘管理卡";
    }
    
    return @"";
}

- (NSString *)imageName {
    
    if (self.cardType == WBCardTypeSwine) {
        return @"swine";
    }
    
    if (self.cardType == WBCardTypeSwinery) {
        return @"swinery";
    }
    
    if (self.cardType == WBCardTypeDieOut) {
        return @"dieout";
    }
    
    return @"swine";
}

- (NSString *)messageInfo {
    
    if (self.count.count != 0) {
        
        if (self.cardType == WBCardTypeSwine) return @"您已经记录猪只";
        if (self.cardType == WBCardTypeSwinery) return @"您已记录猪群";
        if (self.cardType == WBCardTypeDieOut) return @"您已记录死淘";
    }
    
    if (self.cardType == WBCardTypeSwine) return @"记录猪只健康卡，进行科学智能化猪只管理";
    if (self.cardType == WBCardTypeSwinery) return @"记录猪群健康卡，可更高效进行免疫、保健、治疗等工作";
    if (self.cardType == WBCardTypeDieOut) return @"进行死淘跟踪管理，可有效降低区域生物安全事件发生";
    
    return @"";
}

- (NSString *)message {
    
    if (self.count.count != 0) {
        
        if (self.cardType == WBCardTypeSwine) {
            
            int sum = 0;
            for (NSString *key in self.count) {
                
                sum += [self.count[key] intValue];
            }
            
            return [NSString stringWithFormat:@"%d 头", sum];
        }
        
        if (self.cardType == WBCardTypeSwinery) {
            
            int sum = 0;
            for (NSString *key in self.count) {
                
                sum += [self.count[key] intValue];
            }
            
            return [NSString stringWithFormat:@"%d 批次", sum];
        }
        
        if (self.cardType == WBCardTypeDieOut) {
            
            int sum = 0;
            for (NSString *key in self.count) {
                
                sum += [self.count[key] intValue];
            }
            
            return [NSString stringWithFormat:@"%d 条", sum];
        }
    }
    
    return @"";
}

- (NSString *)subMessage {
    
    if (self.count.count != 0) {
        
        if (self.cardType == WBCardTypeSwine) {
            
            NSMutableString *str = [NSMutableString string];
            if (self.count[@"3"]) {
                
                // 公猪
                [str appendFormat:@"公猪 %@ 头 ", self.count[@"3"]];
            }
            
            if (self.count[@"4"]) {
                
                // 母猪
                if (str.length > 0) [str appendString:@"| "];
                [str appendFormat:@"母猪 %@ 头 ", self.count[@"4"]];
            }
            
            return [NSString stringWithFormat:@"( %@)", str];
        }
        
        if (self.cardType == WBCardTypeSwinery) {
            
            NSMutableString *str = [NSMutableString string];
            if (self.count[@"0"]) {
                
                // 在场
                [str appendFormat:@"在场 %@ 批次 ", self.count[@"0"]];
            }
            
            if (self.count[@"1"]) {
                
                // 离场
                if (str.length > 0) [str appendString:@"| "];
                [str appendFormat:@"离场 %@ 批次 ", self.count[@"1"]];
            }
            
            return [NSString stringWithFormat:@"( %@)", str];
        }
        
        if (self.cardType == WBCardTypeDieOut) {
            
            NSMutableString *str = [NSMutableString string];
            if (self.count[@"swine"]) {
                
                // 在场
                [str appendFormat:@"猪只 %@ 条 ", self.count[@"swine"]];
            }
            
            if (self.count[@"herd"]) {
                
                // 离场
                if (str.length > 0) [str appendString:@"| "];
                [str appendFormat:@"猪群 %@ 条 ", self.count[@"herd"]];
            }
            
            return [NSString stringWithFormat:@"( %@)", str];
        }
    }
    
    return @"";
}

- (NSString *)tips {
    
    NSString *option = self.option;
    if ([@"add_swine" isEqualToString:self.option]) {
        option = @"新增了猪只健康卡";
    }
    if ([@"add_herd" isEqualToString:self.option]) {
        option = @"新增了猪群健康卡";
    }
    if ([@"add_dieout" isEqualToString:self.option]) {
        option = @"新增猪只/猪群死淘记录";
    }
    if ([@"add_immune" isEqualToString:self.option]) {
        
        if (self.cardType == WBCardTypeSwine) {
            option = @"记录了猪只免疫信息";
        }
        if (self.cardType == WBCardTypeSwinery) {
            option = @"记录了猪群免疫信息";
        }
    }
    if ([@"add_care" isEqualToString:self.option]) {
        
        if (self.cardType == WBCardTypeSwine) {
            option = @"记录了猪只保健信息";
        }
        if (self.cardType == WBCardTypeSwinery) {
            option = @"记录了猪群保健信息";
        }
    }
    if ([@"add_treatment" isEqualToString:self.option]) {
        
        if (self.cardType == WBCardTypeSwine) {
            option = @"记录了猪只治疗信息";
        }
        if (self.cardType == WBCardTypeSwinery) {
            option = @"记录了猪群治疗信息";
        }
    }
    if ([@"add_note" isEqualToString:self.option]) {
        
        if (self.cardType == WBCardTypeSwine) {
            option = @"添加了猪只笔记信息";
        }
        if (self.cardType == WBCardTypeSwinery) {
            option = @"添加了猪群笔记信息";
        }
    }
    
    return option;
}

- (NSString *)dateMsg {
    
    if (self.updateTime != nil) {
        
        NSDate *date = [NSDate dateWithTimeIntervalSince1970:[self.updateTime integerValue]];
        NSString *dateInfo = [NSString timeStringFromFormat:@"MM/dd" withDate:date];
        
        return dateInfo;
    }
    
    return @"";
}

@end
